package com.hyzh.latte.vehicle.controller;

import com.coffee.core.CoffeeResponse;
import com.coffee.core.CoffeeResponseEnum;
import com.hyzh.latte.sandtable.pojo.Vector_Point_2D;
import com.hyzh.latte.sandtable.service.GeoQueryService;
import com.hyzh.latte.vehicle.dmo.ParkRoadEnum;
import com.hyzh.latte.vehicle.dmo.ShortestRoadRequest;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @author songkui
 * @since 2024/4/12 19:08
 */
@RestController
@RequestMapping("/track")
@Slf4j
@AllArgsConstructor
//@CrossOrigin
public class VehicleTrackController {


    private final GeoQueryService geoQueryService;
    @PostMapping("/shortest-road")
    public CoffeeResponse<List<Vector_Point_2D>> findShortestRoad(@RequestHeader("park") String park, @RequestBody ShortestRoadRequest request) {
        try {
            String area = Objects.requireNonNull(ParkRoadEnum.ofCode(park)).road();
            List<Vector_Point_2D> resultPoints = geoQueryService.findShortestRoad(new Vector_Point_2D(request.getStartLon(), request.getStartLat()),
                    new Vector_Point_2D(request.getEndLon(), request.getEndLat()), area);
            return CoffeeResponse.responseSuccess(resultPoints);
        } catch (Exception e) {
            log.error("eoro", e);
            return CoffeeResponse.response(CoffeeResponseEnum.NotData);
        }
    }


}
